home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / IO::Socket.z / IO::Socket
Encoding:
Text File  |  1998-10-30  |  9.8 KB  |  331 lines

  1.  
  2.  
  3.  
  4. IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))                                                    IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      IO::Socket - Object interface to socket communications
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.          use IO::Socket;
  13.  
  14.  
  15. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  16.      IO::Socket provides an object interface to creating and using sockets. It
  17.      is built upon the the _I_O::_H_a_n_d_l_e manpage interface and inherits all the
  18.      methods defined by the _I_O::_H_a_n_d_l_e manpage.
  19.  
  20.      IO::Socket only defines methods for those operations which are common to
  21.      all types of socket. Operations which are specified to a socket in a
  22.      particular domain have methods defined in sub classes of IO::Socket
  23.  
  24.      IO::Socket will export all functions (and constants) defined by the
  25.      _S_o_c_k_e_t manpage.
  26.  
  27. CCCCOOOONNNNSSSSTTTTRRRRUUUUCCCCTTTTOOOORRRR
  28.      new ( [ARGS] )
  29.          Creates an IO::Socket, which is a reference to a newly created symbol
  30.          (see the Symbol package). new optionally takes arguments, these
  31.          arguments are in key-value pairs.  new only looks for one key Domain
  32.          which tells new which domain the socket will be in. All other
  33.          arguments will be passed to the configuration method of the package
  34.          for that domain, See below.
  35.  
  36.          IO::Sockets will be in autoflush mode after creation.  Note that
  37.          versions of IO::Socket prior to 1.1603 (as shipped with Perl
  38.          5.004_04) did not do this.   So if you need backward compatibility,
  39.          you should set autoflush explicitly.
  40.  
  41. MMMMEEEETTTTHHHHOOOODDDDSSSS
  42.      See the _p_e_r_l_f_u_n_c manpage for complete descriptions of each of the
  43.      following supported IO::Socket methods, which are just front ends for the
  44.      corresponding built-in functions:
  45.  
  46.          socket
  47.          socketpair
  48.          bind
  49.          listen
  50.          accept
  51.          send
  52.          recv
  53.          peername (getpeername)
  54.          sockname (getsockname)
  55.  
  56.      Some methods take slightly different arguments to those defined in the
  57.      _p_e_r_l_f_u_n_c manpage in attempt to make the interface more flexible. These
  58.      are
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))                                                    IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))
  71.  
  72.  
  73.  
  74.      accept([PKG])
  75.          perform the system call accept on the socket and return a new object.
  76.          The new object will be created in the same class as the listen
  77.          socket, unless PKG is specified. This object can be used to
  78.          communicate with the client that was trying to connect. In a scalar
  79.          context the new socket is returned, or undef upon failure. In an
  80.          array context a two-element array is returned containing the new
  81.          socket and the peer address, the list will be empty upon failure.
  82.  
  83.          Additional methods that are provided are
  84.  
  85.      timeout([VAL])
  86.          Set or get the timeout value associated with this socket. If called
  87.          without any arguments then the current setting is returned. If called
  88.          with an argument the current setting is changed and the previous
  89.          value returned.
  90.  
  91.      sockopt(OPT [, VAL])
  92.          Unified method to both set and get options in the SOL_SOCKET level.
  93.          If called with one argument then getsockopt is called, otherwise
  94.          setsockopt is called.
  95.  
  96.      sockdomain
  97.          Returns the numerical number for the socket domain type. For example,
  98.          for a AF_INET socket the value of &AF_INET will be returned.
  99.  
  100.      socktype
  101.          Returns the numerical number for the socket type. For example, for a
  102.          SOCK_STREAM socket the value of &SOCK_STREAM will be returned.
  103.  
  104.      protocol
  105.          Returns the numerical number for the protocol being used on the
  106.          socket, if known. If the protocol is unknown, as with an AF_UNIX
  107.          socket, zero is returned.
  108.  
  109. SSSSUUUUBBBB----CCCCLLLLAAAASSSSSSSSEEEESSSS
  110.      IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt::::::::IIIINNNNEEEETTTT
  111.  
  112.      IO::Socket::INET provides a constructor to create an AF_INET domain
  113.      socket and some related methods. The constructor can take the following
  114.      options
  115.  
  116.          PeerAddr    Remote host address          <hostname>[:<port>]
  117.          PeerPort    Remote port or service       <service>[(<no>)] | <no>
  118.          LocalAddr   Local host bind address      hostname[:port]
  119.          LocalPort   Local host bind port         <service>[(<no>)] | <no>
  120.          Proto       Protocol name (or number)    "tcp" | "udp" | ...
  121.          Type        Socket type                  SOCK_STREAM | SOCK_DGRAM | ...
  122.          Listen      Queue size for listen
  123.          Reuse       Set SO_REUSEADDR before binding
  124.          Timeout     Timeout value for various operations
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))                                                    IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))
  137.  
  138.  
  139.  
  140.      If Listen is defined then a listen socket is created, else if the socket
  141.      type, which is derived from the protocol, is SOCK_STREAM then _c_o_n_n_e_c_t()
  142.      is called.
  143.  
  144.      The PeerAddr can be a hostname or the IP-address on the "xx.xx.xx.xx"
  145.      form.  The PeerPort can be a number or a symbolic service name.  The
  146.      service name might be followed by a number in parenthesis which is used
  147.      if the service is not known by the system.  The PeerPort specification
  148.      can also be embedded in the PeerAddr by preceding it with a ":".
  149.  
  150.      If Proto is not given and you specify a symbolic PeerPort port, then the
  151.      constructor will try to derive Proto from the service name.  As a last
  152.      resort Proto "tcp" is assumed.  The Type parameter will be deduced from
  153.      Proto if not specified.
  154.  
  155.      If the constructor is only passed a single argument, it is assumed to be
  156.      a PeerAddr specification.
  157.  
  158.      Examples:
  159.  
  160.         $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
  161.                                       PeerPort => 'http(80)',
  162.                                       Proto    => 'tcp');
  163.  
  164.         $sock = IO::Socket::INET->new(PeerAddr => 'localhost:smtp(25)');
  165.  
  166.         $sock = IO::Socket::INET->new(Listen    => 5,
  167.                                       LocalAddr => 'localhost',
  168.                                       LocalPort => 9000,
  169.                                       Proto     => 'tcp');
  170.  
  171.         $sock = IO::Socket::INET->new('127.0.0.1:25');
  172.  
  173.  
  174.      MMMMEEEETTTTHHHHOOOODDDDSSSS
  175.  
  176.      sockaddr ()
  177.          Return the address part of the sockaddr structure for the socket
  178.  
  179.      sockport ()
  180.          Return the port number that the socket is using on the local host
  181.  
  182.      sockhost ()
  183.          Return the address part of the sockaddr structure for the socket in a
  184.          text form xx.xx.xx.xx
  185.  
  186.      peeraddr ()
  187.          Return the address part of the sockaddr structure for the socket on
  188.          the peer host
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))                                                    IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))
  203.  
  204.  
  205.  
  206.      peerport ()
  207.          Return the port number for the socket on the peer host.
  208.  
  209.      peerhost ()
  210.          Return the address part of the sockaddr structure for the socket on
  211.          the peer host in a text form xx.xx.xx.xx
  212.  
  213.      IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt::::::::UUUUNNNNIIIIXXXX
  214.  
  215.      IO::Socket::UNIX provides a constructor to create an AF_UNIX domain
  216.      socket and some related methods. The constructor can take the following
  217.      options
  218.  
  219.          Type        Type of socket (eg SOCK_STREAM or SOCK_DGRAM)
  220.          Local       Path to local fifo
  221.          Peer        Path to peer fifo
  222.          Listen      Create a listen socket
  223.  
  224.  
  225.      MMMMEEEETTTTHHHHOOOODDDDSSSS
  226.  
  227.      hostpath()
  228.          Returns the pathname to the fifo at the local end
  229.  
  230.      peerpath()
  231.          Returns the pathanme to the fifo at the peer end
  232.  
  233. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  234.      the _S_o_c_k_e_t manpage, the _I_O::_H_a_n_d_l_e manpage
  235.  
  236. AAAAUUUUTTTTHHHHOOOORRRR
  237.      Graham Barr <_G_r_a_h_a_m._B_a_r_r@_t_i_u_k._t_i._c_o_m>
  238.  
  239. CCCCOOOOPPPPYYYYRRRRIIIIGGGGHHHHTTTT
  240.      Copyright (c) 1996 Graham Barr. All rights reserved. This program is free
  241.      software; you can redistribute it and/or modify it under the same terms
  242.      as Perl itself.
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))                                                    IIIIOOOO::::::::SSSSoooocccckkkkeeeetttt((((3333))))
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.                                                                         PPPPaaaaggggeeee 5555
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.